Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2gameBefore = require("gameBefore");
var $2EventCenter = require("EventCenter");
var def_BannerMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.OnShowCallback = new Map();
    this.OnDestroyCallback = new Map();
    this.OnHideCallback = new Map();
    this.bannerAds = new Map();
    this.rects = new Map();
    this.isDestroy = true;
    this.isError = false;
    this.showing = "";
  }
  return babel_createClass(_ctor, [{
    key: "Init",
    value: function Init(e) {
      this.bannerId = e;
    }
  }, {
    key: "Create",
    value: function Create(e, t) {
      console.log("Create bannerID:", e, t);
      if (window.wx && !this.bannerAds.has(e)) {
        var _n = {};
        if (t) {
          _n = t;
        } else {
          if (!this.rects.has(e)) {
            console.log(t);
            return void console.error("BannerMgr Create no rect !");
          }
          _n = this.rects.get(e);
        }
        var _i = wx.getSystemInfoSync().windowHeight - _n.width / 16 * 9;
        console.log("top:", _i);
        var _s = wx.createBannerAd({
          adUnitId: e,
          style: {
            width: _n.width,
            left: 0,
            top: _i
          },
          adIntervals: 90
        });
        _s.style.left = (wx.getSystemInfoSync().windowWidth - _n.width) / 2;
        _s.onLoad(function () {});
        _s.onError(function (e) {
          console.log("onError", e);
          cc.Canvas.instance.node.getComponent($2gameBefore.default).IsBannerShow = false;
        });
        _s.onResize(function (e) {
          console.log("size++++", e.width, e.height, _s);
          var t = wx.getSystemInfoSync().windowHeight - e.height;
          console.log("top2:", t);
          var o = (wx.getSystemInfoSync().windowWidth - e.width) * _n.widthPercent;
          console.log("left:", o);
          _s.style.top = t;
          _s.style.left = o;
        });
        this.bannerAds.set(e, _s);
      }
    }
  }, {
    key: "CreateAndShow",
    value: function CreateAndShow(e, t) {
      this.Create(e, t);
      this.Show(e, t);
    }
  }, {
    key: "refreshAD",
    value: function refreshAD(e, t) {
      console.log(t);
      this.Destroy(e);
      null != t && this.rects.delete(e);
      this.CreateAndShow(e, t);
    }
  }, {
    key: "Show",
    value: function Show(e, t) {
      if (this.bannerAds.has(e)) {
        console.log("BannerMgr show", e);
        this.bannerAds.get(e).show().then(function () {
          console.log("广告显示成功");
          $2EventCenter.default.postEvent("bannershow");
        }).catch(function (e) {
          console.log("广告组件出现问题", e);
        });
        "" == this.showing && (this.showing = e);
        this.OnShowCallback.has(e) && this.OnShowCallback.get(e)();
      } else {
        window.wx && this.CreateAndShow(e, t);
      }
    }
  }, {
    key: "Hide",
    value: function Hide(e) {
      if (this.bannerAds.has(e)) {
        this.bannerAds.get(e).hide();
        this.showing == e && (this.showing = "");
        this.OnHideCallback.has(e) && this.OnHideCallback.get(e)();
      }
    }
  }, {
    key: "tempHide",
    value: function tempHide() {
      console.log("tempHide", this.showing);
      if ("" != this.showing && this.bannerAds.has(this.showing)) {
        this.bannerAds.get(this.showing).hide();
        this.OnHideCallback.has(this.showing) && this.OnHideCallback.get(this.showing)();
      }
    }
  }, {
    key: "tempShow",
    value: function tempShow() {
      "" != this.showing && this.Show(this.showing);
    }
  }, {
    key: "Destroy",
    value: function Destroy(e) {
      if (this.bannerAds.has(e)) {
        this.showing == e && (this.showing = "");
        this.OnDestroyCallback.has(e) && this.OnDestroyCallback.get(e)();
        this.bannerAds.get(e).offLoad(function (e) {
          console.log(e);
        });
        this.bannerAds.get(e).offError(function (e) {
          console.log(e);
        });
        this.bannerAds.get(e).offResize(function (e) {
          console.log(e);
        });
        this.bannerAds.get(e).destroy();
        this.bannerAds.delete(e);
      }
    }
  }, {
    key: "RealWidth",
    get() {
      return 0;
    }
  }, {
    key: "RealHeight",
    get() {
      return 0;
    }
  }], [{
    key: "Instance",
    get() {
      _ctor._instance || (_ctor._instance = new _ctor());
      return _ctor._instance;
    }
  }]);
}();
exports.default = def_BannerMgr;